package com.zeny.express.framework.webapp.tiles;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.ApplicationResource;

public class CompleteAutoloadTilesContainerFactory extends
		org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory {

	@Override
	protected List<ApplicationResource> getSources(
			ApplicationContext applicationContext) {
		Collection<ApplicationResource> webINFSet = applicationContext
				.getResources("classpath:/tiles*.xml");
		Collection<ApplicationResource> metaINFSet = applicationContext
				.getResources("classpath*:/com/zeny/express/module/**/META-INF/**/tiles*.xml");

		List<ApplicationResource> filteredResources = new ArrayList<ApplicationResource>();
		if (webINFSet != null) {
			for (ApplicationResource resource : webINFSet) {
				if (Locale.ROOT.equals(resource.getLocale())) {
					filteredResources.add(resource);
				}
			}
		}
		if (metaINFSet != null) {
			for (ApplicationResource resource : metaINFSet) {
				if (Locale.ROOT.equals(resource.getLocale())) {
					filteredResources.add(resource);
				}
			}
		}
		return filteredResources;
	}

}
